/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.cx1.dao.impl;

import com.ibatis.sqlmap.client.SqlMapClient;
import org.cx1.dao.api.ITransactionDao;
import org.cx1.model.Transaction;

/**
 *
 * @author ECH
 */
public class TransactionDao implements ITransactionDao {

    private SqlMapClient sqlMapClient;

    public TransactionDao() {
        sqlMapClient = IbatisConnectionFactory.getSqlMapClient();
    }
    
    @Override
    public Transaction getById(String id) {
        Transaction transaction = null;        
        try {
            transaction = (Transaction) sqlMapClient.queryForObject("transaction.getById", id);
        } catch (Exception ex) {
            ex.printStackTrace();
        }        
        return transaction;
    }

    @Override
    public String add(Transaction transaction) {
        String transactionId = "";        
        try {
            sqlMapClient.insert("transaction.add", transaction);
            transactionId = transaction.getId();            
        } 
        catch (Exception ex) {
            ex.printStackTrace();
        }        
        return transactionId;
    }

    @Override
    public int deleteById(String id) {
        int noOfRowsAffected = 0;        
        try {
            noOfRowsAffected = sqlMapClient.delete("transaction.deleteById", id);
        } catch (Exception ex) {
            ex.printStackTrace();
        }        
        return noOfRowsAffected;
    }
    
}
